<{include file="public/header.html"}>
<header class="bj-white search-page follow-head">
    <a href="<{eval url('account')}>" class="icon-return iconfont title-top title-left">&#xe604;</a>
    <h1 class="bar-title">我的领取</h1>
    <a href="<{eval url('task')}>" class="bead-share">任务</a>
</header>
<div class="wenda-page mt50">
    <div class="wenda-con">
        <div class="wenda-ul disblock">
            <ul class="ask" id="content-list" style="border-top: 6px solid #eee;">
            </ul>
            <div class="loading pt50" id="noresults" style="display: none;">
                <a href="javascript:;" class="load-success empty-load">
                    <div class="pic"><img src="<{$style_dir}>/img/none/3.jpg" alt=""/></div>
                    <p>您还没有领取过任何任务，<a href="/task.html">去领取</a></p>
                </a>
            </div>
            <div class="loading" id="loading" style="display: none;">
                <a class="/*pull-load*/ load-success" href="javascript:;">加载中...</a>
            </div>
            <div class="loading" id="nomoreresults" style="display: none;">
                <a href="javascript:;" class="load-success nomore-load">已经到底啦~~~</a>
            </div>
        </div>
    </div>
</div>
<div class="public-field-bj publick-jq2" id="alert_mes">
    <div class="public-field-phone w100" id="alert_mes_cont" style="bottom: 5px;">
        <div class="plr15">
            <ul class="bj-white">
                <li data-type="0">确认取消该任务？</li>
            </ul>
            <button class="btn bj-white mt5" id="delete-bind" data-id=""
                    style="border-radius: 12px;width: 49%;color:#d70e0e">确认
            </button>
            <button class="btn bj-white mt5 close-jq _close" style="border-radius: 12px;width: 49%;">取消</button>
        </div>
    </div>
</div>
<div class="public-field-bj publick-jq2" id="alert_mes2">
    <div class="public-field-phone w100" id="alert_mes2_cont" style="bottom: 5px;">
        <div class="plr15">
            <ul class="bj-white">
                <li data-type="0">确认结束该任务？</li>
            </ul>
            <button class="btn bj-white mt5" id="delete2-bind" data-id=""
                    style="border-radius: 12px;width: 49%;color:#d70e0e">确认
            </button>
            <button class="btn bj-white mt5 close-jq _close" style="border-radius: 12px;width: 49%;">取消</button>
        </div>
    </div>
</div>
<script type="text/javascript" src="/static/js/emotions.js"></script>
<script type="text/javascript" src="/static/js/taskrec_scrollpagination.js"></script>
<script type="text/javascript" src="/static/js/account-min-1.0.js"></script>
<script type="text/javascript">
    function apply_finish(tid,sid) {
        $("#alert_mes2").stop().fadeIn();
        $("#alert_mes2").click(function () {
            $("#alert_mes2").stop().fadeOut();
        });
        $("#delete2-bind").on("click", function () {
            $.ajax({
                type: 'POST',
                url: '/task/end_subtask.html',
                data: {tid: tid, sid: sid},
                dataType: "json",
                success: function (result) {
                    $.mvalidateTip(result.msg);
                    setTimeout(function () {
                        location.reload();
                    }, 2000);
                }
            });
        });
    }
    $(function () {
        var currentPage = 0;
        $('#content-list').scrollPagination({
            'contentPage': "/account/taskrec",
            'contentData': {
                'pageIndex': currentPage,
                'uuid': is_login.uuid
            },
            'scrollTarget': $(window),
            'heightOffset': 0,
            'beforeLoad': function () { // before load function, you can display a preloader div
                $('#loading').fadeIn('fast');
                $('#loading').attr('scrollpagination', 'disabled');
            },
            'afterLoad': function (elementsLoaded) { // after loading content, you can use this function to animate your new elements
                $('#loading').fadeOut('fast');
                $('#loading').attr('scrollpagination', 'enabled');
                if (elementsLoaded.length == 0) {
                    if (currentPage != 0) {
                        $('#nomoreresults').fadeIn('slow');
                    }
                    $('#content-list').stopScrollPagination();
                } else {
                    currentPage = currentPage + 1;
                }
                if (elementsLoaded.length == 0 && currentPage == 0) {
                    $("#noresults").fadeIn('slow');
                } else {
                    for (var i = 0; i < elementsLoaded.length; i++) {
                        var str = AnalyticEmotion(elementsLoaded[i].innerHTML);
                        elementsLoaded[i].innerHTML = str;
                    }
                    this.contentData.pageIndex = currentPage;
                    $(elementsLoaded).fadeInWithDelay();
                }

                if ($('#content-list').children().length > 100) { // if more than 100 results already loaded, then stop pagination (only for testing)
                    $('#nomoreresults').fadeIn();
                    $('#content-list').stopScrollPagination();
                }
                $("#type_on").click(function () {
                    var data_id = $(this).attr("data-id");
                    $("#delete-bind").attr("data-id", data_id);
                    $("#alert_mes").stop().fadeIn();
                });
                $("#alert_mes").click(function () {
                    $("#alert_mes").stop().fadeOut();
                });
                $("#delete-bind").on("click", function () {
                    var id = $(this).attr("data-id");
                    $.ajax({
                        type: 'POST',
                        url: '/task/ajax_cancel_apply.html',//发送请求
                        data: {tid: id},
                        dataType: "json",
                        success: function (resp) {
                            if (resp.reqStatus) {
                                $.mvalidateTip(resp.msg);
                                setTimeout(function () {
                                    location.reload();
                                }, 2000);
                            } else {
                                $.mvalidateTip(resp.msg);
                                setTimeout(function () {
                                    location.href=resp.link;
                                }, 2000);
                            }
                        }
                    });
                });
            }
        });
        $.fn.fadeInWithDelay = function () {
            var delay = 0;
            return this.each(function () {
                $(this).delay(delay).animate({
                    opacity: 1
                }, 200);
                delay += 100;
            });
        };
    });
</script>
<{include file="public/footer.html"}> 